package com.jake.xpage.router;

import androidx.annotation.NonNull;

import com.jake.xpage.page.IPageAnimator;
import com.jake.xpage.page.XPageArgument;

/**
 * 路由信息
 */
public class XPageRoute {

    /**
     * 模块
     */
    @NonNull
    public final String module;
    /**
     * 路径
     */
    @NonNull
    public final String url;
    /**
     * 参数
     */
    public XPageArgument argument;
    public IPageAnimator animator;

    public XPageRoute(@NonNull String module, @NonNull String url) {
        this.module = module;
        this.url = url;
    }

    public XPageRoute setArgument(XPageArgument argument) {
        this.argument = argument;
        return this;
    }

    public XPageRoute setPageAnimator(IPageAnimator animator) {
        this.animator = animator;
        return this;
    }

    public XPageRoute setExtraObject(Object value) {
        if (this.argument == null) {
            this.argument = new XPageArgument();
        }
        this.argument.extraObject = value;
        return this;
    }


    public static XPageRoute obtain(@NonNull String url) {
        return obtain(XPageRouteMapperManager.DEFAULT_ROUTE_MODULE, url);
    }

    public static XPageRoute obtain(@NonNull String module, @NonNull String url) {
        return new XPageRoute(module, url);
    }

    public static XPageRoute obtain(@NonNull String module, @NonNull String path, XPageArgument argument) {
        return obtain(module, path).setArgument(argument);
    }
}
